﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SenderData", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(SenderData))]
    public class SenderDataSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISenderData clazz;
        
        public SenderDataSerializer(ISenderData clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("SenderCode");
            if (clazz.SenderCode!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.SenderCode.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SenderCode");
            }
            Writer.WriteEndElement();
            if (clazz.SenderName!=null) {
                Writer.WriteStartElement("SenderName");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.SenderName.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="SenderCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SenderData>SenderCode");
                }
                clazz.SenderCode = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("SenderCode"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SenderData>SenderCode", Reader.LocalName);
            }
            if (Reader.LocalName=="SenderName") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SenderData>SenderName");
                }
                clazz.SenderName = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("SenderName"));
            }
        }
    }
}
